from datetime import datetime
from typing import Optional

from pydantic import BaseModel

from app.schemas.base_model import OrmBaseModel


class InstrumentBase(OrmBaseModel):
    id: Optional[int]
    symbol: Optional[str]
    name: Optional[str]
    quote: Optional[str]
    base: Optional[str]
    pricePrecision: Optional[int]
    amountPrecision: Optional[int]
    symbolPartition: Optional[str]
    industry: Optional[str]
    area: Optional[str]
    nameLetter: Optional[str]
    marketType: Optional[str]
    createdDate: Optional[datetime]
    updatedDate: Optional[datetime]

# '{"amount": 0, "price": 4, "base": 8, "quote": 8}'
class Precision(BaseModel):
    amount: Optional[int]
    price: Optional[int]
    base: Optional[int]
    quote: Optional[int]

class InstrumentQuery(InstrumentBase):
    pass

class PickableQuery(BaseModel):
    isSt: Optional[int]
    tradeStatus: Optional[int]
    barDate: datetime
    exchangeId: int
    frequency: str


# 最新
class InstrumentLast(OrmBaseModel):
    id: Optional[int]
    symbol: Optional[str]
    name: Optional[str]
    low: Optional[float]
    high: Optional[float]
    open: Optional[float]
    close: Optional[float]
    volume: Optional[float]
    amount: Optional[float]
    preClose: Optional[float]
    barDate: Optional[datetime]
    favoriteId: Optional[int]
    change:Optional[float]
    precision: Optional[str]

class InstrumentPositionLast(InstrumentLast):
    cost: Optional[float]
    num: Optional[float]
    startDate: Optional[datetime]
    endDate: Optional[datetime]
    state: Optional[str]
    positionId: Optional[int]